package com.aooci.ordercat.desktop.view;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;

import com.aooci.ordercat.desktop.OrdercatMain;
import com.aooci.ordercat.vo.OperatedOrderVo;
import com.aooci.ordercat.vo.TakeawayVo;

@SuppressWarnings("restriction")
public class NewTakeawayPanelController implements Initializable {

	private OrdercatMain ordercatMain;
	private DashboardController dashboardController;


	@FXML private Button closeButton;
	@FXML private Button continueButton;
	

	@FXML
	public void initialize(URL arg0, ResourceBundle arg1) {
		closeButton.setOnAction(new EventHandler<ActionEvent>() {
		    @Override public void handle(ActionEvent actionEvent) {
			    ((Stage)((Node)actionEvent.getSource()).getScene().getWindow()).close();
		    }
		});
		
		continueButton.setOnAction(new EventHandler<ActionEvent>() {
		    @Override public void handle(ActionEvent actionEvent) {
				OperatedOrderVo operatedOrderVo = ordercatMain.getOrderOperationService().createTakeawayOrder();
				TakeawayVo takeawayVo = new TakeawayVo(operatedOrderVo.getTakeaway());
				dashboardController.getTakeawayTable().getItems().add(takeawayVo);
				dashboardController.openOrderOperationDialog(operatedOrderVo);
				((Stage)((Node)actionEvent.getSource()).getScene().getWindow()).close();
		    }
		});
	}


	public void setOrdercatMain(OrdercatMain ordercatMain) {
		this.ordercatMain = ordercatMain;
	}

	public void setDashboardController(DashboardController dashboardController) {
		this.dashboardController = dashboardController;
	}
}
